package com.reebake.ideal.permission.controller.client;

import cn.hutool.core.bean.BeanUtil;
import com.reebake.ideal.permission.client.MenuClient;
import com.reebake.ideal.permission.constant.MenuTypeConstants;
import com.reebake.ideal.permission.entity.Menu;
import com.reebake.ideal.permission.entity.MenuDTO;
import com.reebake.ideal.permission.service.PermissionAuthService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("menu")
@RequiredArgsConstructor
public class MenuClientController implements MenuClient {
    private final PermissionAuthService permissionAuthService;

    @Override
    public List<String> queryAccessCodeByUserId(String userId) {
        List<Menu> menus = permissionAuthService.queryMenuByUserId(userId, MenuTypeConstants.ACTION);
        return menus.stream().map(Menu::getAccessCode).toList();
    }

    @Override
    public List<MenuDTO> queryMenuByUserId(String userId) {
        List<Menu> menus = permissionAuthService.queryMenuByUserId(userId, MenuTypeConstants.MENU);
        return BeanUtil.copyToList(menus, MenuDTO.class);
    }

}
